****************
*** PANEL A ****
****************
clear all 
set more off
cd "/Users/yasenov/Dropbox/mariel_boatlift/jhr_version/jhr_figures"
global folder /Users/yasenov/Dropbox/mariel_boatlift/revision_version/revision_data/

use fig7a.dta, clear

/* standardize all to 0 in 1979 */
rename te_miami te100
keep year te*
keep if year != .
reshape long te, i(year) j(city)
sort city year
by city: gen v = te[7]
replace te = te - v
drop v
reshape wide te, i(year) j(city)
/*			*/

reshape long te, i(year) j(city)
sort city year	
by city: gen rmspe_ratio_7279 = ((te[8]^2+te[9]^2+te[10]^2)/3) / ((te[1]^2+te[2]^2+te[3]^2+te[4]^2+te[5]^2+te[6]^2+te[7]^2) / 7)
by city: gen rmspe_ratio_7779 = ((te[8]^2+te[9]^2+te[10]^2)/3) / ((te[5]^2+te[6]^2+te[7]^2)/3)
collapse rmspe_ratio_7279 rmspe_ratio_7779, by(city)

* Rows 1-3, Column 1 for Table with Post-Pre RMSPE Ratios
sort rmspe_ratio_7279
gen n = _n
list n rmspe_ratio_7279 if city == 100
qui sum n if city == 100
di "p-value for post-pre rmspe ratio is =  " 1 - r(mean)/42 
drop n

* Rows 4-6, Column 1 for Table with Post-Pre RMSPE Ratios
sort rmspe_ratio_7779
gen n = _n
list n rmspe_ratio_7779 if city == 100
qui sum n if city == 100
di "p-value for post-pre rmspe ratio is =  " 1 - r(mean)/42  
drop n

****************
*** PANEL B ****
****************
use fig7b.dta, clear 

/* standardize all to 0 in 1979 */
rename te_miami te100
keep year te*
keep if year != .
reshape long te, i(year) j(city)
sort city year
by city: gen v = te[7]
replace te = te - v
drop v
reshape wide te, i(year) j(city)
/*			*/

reshape long te, i(year) j(city)
sort city year	
by city: gen rmspe_ratio_7279 = ((te[8]^2+te[9]^2+te[10]^2)/3) / ((te[1]^2+te[2]^2+te[3]^2+te[4]^2+te[5]^2+te[6]^2+te[7]^2) / 7)
by city: gen rmspe_ratio_7779 = ((te[8]^2+te[9]^2+te[10]^2)/3) / ((te[5]^2+te[6]^2+te[7]^2)/3)
collapse rmspe_ratio_7279 rmspe_ratio_7779, by(city)

* Rows 1-3, Column 2 for Table with Post-Pre RMSPE Ratios
sort rmspe_ratio_7279
gen n = _n
list n rmspe_ratio_7279 if city == 100
qui sum n if city == 100
di "p-value for post-pre rmspe ratio is =  " 1 - r(mean)/43 
drop n

* Rows 4-6, Column 2 for Table with Post-Pre RMSPE Ratios
sort rmspe_ratio_7779
gen n = _n
list n rmspe_ratio_7779 if city == 100
qui sum n if city == 100
di "p-value for post-pre rmspe ratio is =  " 1 - r(mean)/43  
drop n

****************
*** PANEL C ****
****************
use fig7c.dta, clear 

/* standardize all to 0 in 1979 */
rename te_miami te100
keep year te*
keep if year != .
reshape long te, i(year) j(city)
sort city year
by city: gen v = te[7]
replace te = te - v
drop v
reshape wide te, i(year) j(city)
/*			*/

reshape long te, i(year) j(city)
sort city year	
by city: gen rmspe_ratio_7279 = ((te[8]^2+te[9]^2+te[10]^2)/3) / ((te[1]^2+te[2]^2+te[3]^2+te[4]^2+te[5]^2+te[6]^2+te[7]^2) / 7)
by city: gen rmspe_ratio_7779 = ((te[8]^2+te[9]^2+te[10]^2)/3) / ((te[5]^2+te[6]^2+te[7]^2)/3)
collapse rmspe_ratio_7279 rmspe_ratio_7779, by(city)

* Rows 1-3, Column 3 for Table with Post-Pre RMSPE Ratios
sort rmspe_ratio_7279
gen n = _n
list n rmspe_ratio_7279 if city == 100
qui sum n if city == 100
di "p-value for post-pre rmspe ratio is =  " 1 - r(mean)/43 
drop n

* Rows 4-6, Column 3 for Table with Post-Pre RMSPE Ratios
sort rmspe_ratio_7779
gen n = _n
list n rmspe_ratio_7779 if city == 100
qui sum n if city == 100
di "p-value for post-pre rmspe ratio is =  " 1 - r(mean)/43  
drop n

****************
*** PANEL D ****
****************	
use fig7d.dta, clear

/* standardize all to 0 in 1979 */
rename te_miami te100
keep year te*
keep if year != .
reshape long te, i(year) j(city)
sort city year
by city: gen v = te[7]
replace te = te - v
drop v
reshape wide te, i(year) j(city)
/*			*/

reshape long te, i(year) j(city)
sort city year	
by city: gen rmspe_ratio_7279 = ((te[8]^2+te[9]^2+te[10]^2)/3) / ((te[1]^2+te[2]^2+te[3]^2+te[4]^2+te[5]^2+te[6]^2+te[7]^2) / 7)
by city: gen rmspe_ratio_7779 = ((te[8]^2+te[9]^2+te[10]^2)/3) / ((te[5]^2+te[6]^2+te[7]^2)/3)
collapse rmspe_ratio_7279 rmspe_ratio_7779, by(city)

* Rows 1-3, Column 4 for Table with Post-Pre RMSPE Ratios
sort rmspe_ratio_7279
gen n = _n
list n rmspe_ratio_7279 if city == 100
qui sum n if city == 100
di "p-value for post-pre rmspe ratio is =  " 1 - r(mean)/44
drop n

* Rows 4-6, Column 4 for Table with Post-Pre RMSPE Ratios
sort rmspe_ratio_7779
gen n = _n
list n rmspe_ratio_7779 if city == 100
qui sum n if city == 100
di "p-value for post-pre rmspe ratio is =  " 1 - r(mean)/44  
drop n
